<template>
	<view>
		<view class="search">
			<view class="search-item" @click="pickShow = true">
				<u-search placeholder="选择车辆筛选"
					shape="square"
					:disabled="true"
					v-model="searchValue"
					:showAction="false"
					@change="searchChange">
				</u-search>
			</view>
			<view class="add-button" @click="searchValue = ''">
				重置
			</view>
		</view>
		<view style="margin-top: 100rpx;" v-if="list.length < 1">
			<u-empty
				text="暂无数据"
				icon="https://www.zxsl.zxmap.cn/zxch-app/2023/07/21/005b6980c9514d1e8e4a0cee0de018e4.png">
			</u-empty>
		</view>
		
		<view>
			<u-swipe-action>
				<u-swipe-action-item
					:disabled="true"
					:options="options" 
					v-for="(item,index) in list" :key="item.id">
					<view class="swipe-action u-border-top u-border-bottom" @click="gotoPage('/subPackTask/work/scgl/ycgl/detail?id='+item.id)">
						<view class="PhotographerBoxL">
							<view class="cu-avatar round xl" :style="'background-image:url('+item.frontImage+')'">
							</view>
							<view class='cu-tag2 margin-top-xs bg-blue radius'>{{item.carNum}}</view>
						</view>
						<view class="PhotographerBoxR">
							<view class="text-sm text-bold">用车日期：{{item.useTime}}</view>
							<view class="text-sm text-grey margin-top-xs">时间段：{{item.timeSlot}}</view>
							<view class="text-sm text-grey margin-top-xs">驾驶人：{{item.userName}}</view>
						</view>
					</view>
				</u-swipe-action-item>
			</u-swipe-action>
		</view>
		
		<u-picker
			:immediateChange="true"
			:show="pickShow"
			:columns="columns"
			@confirm="confirmPick"
			keyName="name"
			@cancel="pickShow = false">
		</u-picker>
		
	</view>
</template>

<script>
	import { getCarNums } from '@/api/car.js'
	import { getList } from '@/api/journal.js'
	export default {
		data() {
			return {
				options:[{}],
				pickShow:false,
				columns:[],
				searchValue:'',
				list:[],
				pageNum:1,
			}
		},
		onLoad() {
			this.getCarNumList()
			this.getJournalList()
		},
		onReachBottom(){
			this.pageNum += 1
			this.getJournalList()
		},
		onPullDownRefresh(){
			this.pageNum = 1
			this.list = []
			this.getJournalList()
			uni.stopPullDownRefresh()
		},
		methods: {
			async getCarNumList(){
				const { data } = await getCarNums();
				if(data.code == 200){
					this.columns = [data.data]
				}
			},
			async getJournalList(){
				let params = {
					carNum:this.searchValue,
					pageNum:this.pageNum,
				}
				const { data } = await getList(params);
				if(data.code == 200 && data.rows.length > 0){
					this.list = [...this.list,...data.rows]
				}
			},
			searchChange(value){
				this.pageNum = 1
				this.list = []
				this.getJournalList()
			},
			confirmPick(e){
				this.searchValue = e.value[0].name
				this.pickShow = false
			},
		}
	}
</script>

<style>
	page{
		background-color: #f6f6f6;
		color: #333333;
	}
	
	.add-button{
		line-height: 104rpx;
		color: #0081ff;
	}
</style>